/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import model.GroupAccount;
import model.SubGroupAccount;

/**
 *
 * @author adriano.lourenco
 */
public class SubGroupAccountDAO implements DAO {

    private final DataSource dataSource;

    public SubGroupAccountDAO() {
        dataSource = new DataSource();
    }

    public void create(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void delete(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void update(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public Object read(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public ArrayList<SubGroupAccount> readByKey(String Key) {
        try {
            String sql = "SELECT * FROM subgroupaccount where groupaccount=? ";

            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);

            ArrayList<SubGroupAccount> listaSubGrupoContas = new ArrayList<SubGroupAccount>();
            
            ps.setString(1,Key);
            
            ResultSet rs = ps.executeQuery();
              

                while (rs.next()) {

                    SubGroupAccount ga = new SubGroupAccount();

                    ga.setId(rs.getString("SubGroupAccount.id"));
                    ga.setDescricao(rs.getString("SubGroupAccount.descricao"));
                    ga.setGroupaccount(rs.getString("SubGroupAccount.groupaccount"));

                    listaSubGrupoContas.add(ga);
                    System.err.println(listaSubGrupoContas);
                }
                return listaSubGrupoContas;
            

        } catch (Exception e) {
            System.err.println("GROUPACCOUNT.READ - " + e.getMessage());
            return null;
        }

    }

    public void closeDAO() {
        dataSource.closeConnection();
    }

}
